﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VeMayBayBUS;
using VeMayBayDTO;
namespace QLVMBProject
{
    public partial class ctrTraCuu : UserControl
    {
        public ctrTraCuu()
        {
            InitializeComponent();
            //san bay di 
            cbSBDi.DataSource = SanBayBUS.GetSanBay();
            cbSBDi.ValueMember = "masanbay";
            cbSBDi.DisplayMember = "tenSanBay";

            //san bay den
            cbSBDen.DataSource = SanBayBUS.GetSanBay();
            cbSBDen.ValueMember = "masanbay";
            cbSBDen.DisplayMember = "tenSanBay";

            // hang ve 
            cbHangVe.DataSource = HangVeBUS.GethangVe();
            cbHangVe.DisplayMember = "tenhangve";
            cbHangVe.ValueMember = "mahangve";
        }

        private void checkSBDI_CheckedChanged(object sender, EventArgs e)
        {
            cbSBDi.Enabled = checkSBDI.Checked;
        }

        private void checkSBDen_CheckedChanged(object sender, EventArgs e)
        {
            cbSBDen.Enabled = checkSBDen.Checked;
        }

        private void checkNgayBay_CheckedChanged(object sender, EventArgs e)
        {
            dtCanDuoiNgayBay.Enabled = checkNgayBay.Checked;
            dtCanTrenNgayBay.Enabled = checkNgayBay.Checked;
        }


        private void checkTGBay_CheckedChanged(object sender, EventArgs e)
        {
            nbCanDuoiTGB.Enabled = checkTGBay.Checked;
            nbCanTrenTGB.Enabled = checkTGBay.Checked;
        }

        private void checkHangVe_CheckedChanged(object sender, EventArgs e)
        {
            cbHangVe.Enabled = checkHangVe.Checked;
        }
        // thoat
        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Parent.Controls.Remove(this);
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            try
            {
                ChuyenBayCtr dieukien = new ChuyenBayCtr();
                dieukien.IsSbDi = checkSBDI.Checked;
                dieukien.SbDi = (int)cbSBDi.SelectedValue;

                dieukien.IsSbDen = checkSBDen.Checked;
                dieukien.SbDen = (int)cbSBDen.SelectedValue;

                dieukien.IsNgayBay = checkNgayBay.Checked;
                dieukien.CanDuoiNgayBay = dtCanDuoiNgayBay.Value;
                dieukien.CanTrenNgayBay = dtCanTrenNgayBay.Value;

                dieukien.IsThoiGianBay = checkTGBay.Checked;
                dieukien.CanDuoiTGBay = Convert.ToInt32(nbCanDuoiTGB.Value);
                dieukien.CanTrenTGBay = Convert.ToInt32(nbCanTrenTGB.Value);

                dieukien.IsHangVe = checkHangVe.Checked;
                dieukien.HangVe = (int)cbHangVe.SelectedValue;
                if (TraCuuChuyenBayBUS.TraCuuChuyenBay(dieukien).Rows.Count == 0)
                {
                    MessageBox.Show("Khong Tim Thay");
                }
                dgHienThi.DataSource = TraCuuChuyenBayBUS.TraCuuChuyenBay(dieukien);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
        
        }

    }
}
